package com.katze.tools.zookeeper.entity;

import com.katze.common.CommonUtils;
import com.katze.common.tree.Node;
import org.apache.zookeeper.data.Stat;

import java.io.File;

public class ZookeeperNode extends Node {

    private static final long serialVersionUID = 2723896970738780222L;

    private Stat stat;

    private String acl;

    public ZookeeperNode(File item) {
        this(item, null, null);
    }

    public ZookeeperNode(File item, Stat stat) {
        this(item, stat, null);
    }

    public ZookeeperNode(File item, Stat stat, String acl){
        setId(CommonUtils.hmacSha1(item.getPath(), "ZookeeperNode"));
        if (item.getPath().equals(File.separator)){
            setPid("0");
            setName("/");
            setPath("/");
        } else {
            setPid(CommonUtils.hmacSha1(item.getParent() , "ZookeeperNode"));
            setName(item.getName());
            if (!"/".equals(File.separator)){
                setPath(item.getPath().replace(File.separator, "/"));
            } else {
                setPath(item.getPath());
            }
        }
        setStat(stat);
        setAcl(acl);
    }

    public Stat getStat() {
        return stat;
    }

    public void setStat(Stat stat) {
        this.stat = stat;
    }

    public String getAcl() {
        return acl;
    }

    public void setAcl(String acl) {
        this.acl = acl;
    }

    public Boolean getLeaf() {
        return stat == null || stat.getNumChildren() == 0;
    }

    public void setLeaf(Boolean leaf) {
    }
}
